/**
 * Handle changed data.
 *
 * @param {Date} oldValue old value
 * @param {Date} newValue new value
 * @param {JSEvent} event the event that triggered the action
 *
 * @returns {Boolean}
 *
 * @properties={typeid:24,uuid:"976F63C1-21D8-4043-92C2-0E5E90499047"}
 */
function onDataChangeDesde(oldValue, newValue, event) {
	var $hoy = application.getServerTimeStamp()
	if (newValue < $hoy)
	{
		globals.DIALOGS.showErrorDialog('Error','Fecha invalida','OK')
		return false
	}
	return true
}

/**
 * Handle changed data.
 *
 * @param {Date} oldValue old value
 * @param {Date} newValue new value
 * @param {JSEvent} event the event that triggered the action
 *
 * @returns {Boolean}
 *
 * @properties={typeid:24,uuid:"C44A1835-4B20-42B4-9432-161B97DEC675"}
 */
function onDataChangeHasta(oldValue, newValue, event) {
	if (newValue < rh_fecha_hora_d)
	{
		globals.DIALOGS.showErrorDialog('Error','Fecha invalida','OK')
		return false
	}
	return true
}

/**
 * Handle record selected.
 *
 * @param {JSEvent} event the event that triggered the action
 *
 * @properties={typeid:24,uuid:"87550FE0-443C-495E-89C8-E152A293EAC2"}
 * @SuppressWarnings(unused)
 */
function onRecordSelection(event) {
	
  	if (rh_hoteles_id != null)
	{
		var $rel = reservahtl_to_hoteles.hoteles_to_hotelhab
		var $nrec = $rel.getSize()
		if ($nrec == 0)
		{
			globals.DIALOGS.showErrorDialog('Error','No existe Tipo de Habitación para este Hotel','OK')
			return
		}
		var $muestra = new Array()
		var $devuelve = new Array()
		for (var i = 1 ; i <= $rel.getSize() ; i++)
		{
				var $reg 		= $rel.getRecord(i)
				var $comercial 	= $reg.hotelhab_th_com
				var $id 		= $reg.hotelhab_th_tari
				$muestra.push($comercial)
				$devuelve.push($id)
		}
		application.setValueListItems('tipohab_manual',$muestra, $devuelve)	
	}	
	//{
		//var $rel = hoteles_to_hotelhab
		//var $tipos_hab = new Array()
		
		//for (var i = 1 ; i <= $rel.getSize() ; i++)
		//{
			//var $reg = $rel.getRecord(i)
			//var $tipo = $reg.tari_desde.substr(9,4)
			//$tipos_hab.push($tipo)
		//}
		//application.setValueListItems('tipos_habitacion',$tipos_hab)
	//}
}

/**
 * Perform the element default action.
 *
 * @param {JSEvent} event the event that triggered the action
 *
 * @properties={typeid:24,uuid:"BF2B7D5E-D24F-4659-9E03-5366E960A937"}
 */
function agregar(event) {
	reservahtl_to_reservahab.newRecord()
	
	var $may = reservahtl_to_reservacab.rc_qmayores
	var $men = reservahtl_to_reservacab.rc_qmenores
	reservahtl_to_reservahab.rb_qty_my = $may
	reservahtl_to_reservahab.rb_qty_mn = $men
    
}

/**
 * Perform the element default action.
 *
 * @param {JSEvent} event the event that triggered the action
 *
 * @properties={typeid:24,uuid:"903F9376-673B-41AF-90C3-1A724742A0BC"}
 */
function eliminar(event) {
	reservahtl_to_reservahab.deleteRecord()
}

/**
 * Perform the element default action.
 *
 * @param {JSEvent} event the event that triggered the action
 *
 * @properties={typeid:24,uuid:"6EDE619C-82AF-4942-B393-4BF5E84930B9"}
 */
function eliminarHotel(event) {
	reservahtl_to_reservahab.deleteAllRecords()
	controller.deleteRecord()
}

/**
 * Perform the element default action.
 *
 * @param {JSEvent} event the event that triggered the action
 *
 * @properties={typeid:24,uuid:"96641488-5CF3-4CE9-9653-E649ED18BEA5"}
 */
function iraRooming(event) {
	forms.rooming_list.controller.loadRecords(rh_reserva_hotel_id)
	forms.rooming_list.controller.show()
}

/**
 * Perform the element default action.
 *
 * @param {JSEvent} event the event that triggered the action
 *
 * @properties={typeid:24,uuid:"44ACFFBB-E6A0-487F-ACFD-9DA6E1D44C6A"}
 */
function IrAConsultaRooming(event) {
	var $sql = 'SELECT hp_psj_id FROM roomingpsj WHERE hp_hab_id IN (SELECT rg_hab_id FROM roominghab WHERE rg_reserva_hotel_id = ?)'
	var $args = [rh_reserva_hotel_id]
	var $ds = databaseManager.getDataSetByQuery('sytek',$sql,$args,-1)//databaseManager.convertToDataSet(reservahtl_to_reservacab.reservacab_to_reservapsj,['rp_reserva_pasaj_id','rp_apellido','rp_nombre'])

	forms.roomingpsj_consulta.controller.loadRecords($ds)
	forms.roomingpsj_consulta.controller.show()
}
